feat: Add run() wrapper with command output assertions#146
Open
aarvio wants to merge 2 commits intobash-unit:mainfrom
Open
feat: Add run() wrapper with command output assertions#146aarvio wants to merge 2 commits intobash-unit:mainfrom
aarvio wants to merge 2 commits intobash-unit:mainfrom
Conversation
added 2 commits
January 25, 2026 18:20
Add a new test pattern for asserting command outputs and exit status through a run() wrapper function and corresponding assertion functions. Addresses issue: bash-unit#134 -------------------------------------- User story suggested pipe syntax: command_under_test | should_display "${expected_pattern}" command_under_test | err_should_contain "${expected_pattern}" Implemented wrapper pattern: run command_under_test && assert_run_output_matches "${expected_pattern}" run command_under_test && assert_run_error_matches "${expected_pattern}" Works also as separate lines: run command_under_test assert_run_output_matches "${expected_pattern}" assert_run_error_matches "${expected_pattern}" The wrapper pattern achieves the same readability while providing more flexibility and reliability. Problem with pipes: - pipes carry only stdout - harder to resolve exit status if needed - can't verify multiple conditions independently Usage Examples -------------- Simple one-liners: run my_script && assert_run_success run my_command && assert_run_output_equals "expected" run failing_cmd && assert_run_status_code 42 Multiple assertions: run my_script.sh input.txt assert_run_success assert_run_output_matches "^Processed.*successfully" assert_run_error_equals ""
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a new test pattern for asserting command outputs and exit status through a run() wrapper function and corresponding assertion functions.
Addresses issue: #134
User story suggested pipe syntax:
command_under_test | should_display "${expected_pattern}"command_under_test | err_should_contain "${expected_pattern}"Implemented wrapper pattern:
run command_under_test && assert_run_output_matches "${expected_pattern}"run command_under_test && assert_run_error_matches "${expected_pattern}"Works also as separate lines:
run command_under_testassert_run_output_matches "${expected_pattern}"assert_run_error_matches "${expected_pattern}"The wrapper pattern achieves the same readability while providing more flexibility and reliability.
Problem with pipes:
Usage Examples
Simple one-liners:
run my_script && assert_run_successrun my_command && assert_run_output_equals "expected"run failing_cmd && assert_run_status_code 42Multiple assertions:
run my_script.sh input.txtassert_run_successassert_run_output_matches "^Processed.*successfully"assert_run_error_equals ""